perm filename JUST[E,ALS]2 blob sn#216590 filedate 1976-05-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	MINTXT TABCNT TABTAB JPARAM JGINIT JGB JGIND JGMAR JGET TJGET
C00016 ENDMK
C⊗;
;MINTXT TABCNT TABTAB JPARAM JGINIT JGB JGIND JGMAR JGET TJGET

MINTXT←←3			;Minimum allowed text length or TAB field
TJSCNT←←2			;Minimum number of spaces to terminate a TAB field
TABCNT←←50			;Allow 40 tabs

IMPURE

JPMARO:	0
JPMAR:	0
JLMAR:	0
JRMAR:	69
JBNUM:	1
JBNUMO:	1

TPMAR0:	0
TPMAR:	0
TLMAR:	0
TRMAR:	69
TBNUM:	1


TABTAB:	BLOCK	TABCNT

PURE
;  Subroutine to read typed-in decimal numbers.
;Returns the number in A, the terminating character in C and
;a count of the number of digits in B.
JPARAM:	SETZB A,B
	SETZ C,
JPAR1:	PUSHJ P,TYI		;Get next character
	POPJ P,			;End of typing
	CAIG C,71
    	CAIGE C,60
	POPJ P,			;Non numeric character
	IMULI A,12
	ADDI A,-"0"(C)
	AOJA B,JPAR1		;B used to indicate some number (may be zero)

;  Subroutine called by JGET and TJGET
;to clear PAR table and to read and store typed-in MAR values.
JGINIT:	MOVMM A,JCNT
	JUMPE A,JGIN1		;No text referencing
	MOVE T,EXTPNT		;To read JPARAM changing instructions.
	MOVEM T,TYIPNT		;Set pointer.
	HRLI C,(<MOVEI C,>)
	MOVEM C,TYIINS
	MOVSI Q,-4
	SKIPN JCNT
	JRST JGIN1	 	;Leave old values if JCNT=0 and no typed value
	SETOM JPMAR(Q)
	AOBJN Q,.-1
	TRNE F,ATTMOD		;Are we in ATTACH mode?
	SKIPA E,[JATAB]		;   Yes so put [JATAB] in E.
	MOVEI E,JPTAB		;   No so put [JPTAB] in E.
	MOVE D,@JPT1(E)		;Put contents of @ATTBUF or @ARRLIN in D.
	HRRZM D,JPTR#		;Location of first line to examine
	MOVE A,JLPTR(E)		;Number of lines
	TRNE F,ATTMOD
	JRST JGIN0
	SUB A,ARRL
	ADDI A,1
JGIN0:	CAMGE A,JCNT
	MOVEM A,JCNT		;Limit number of lines to the available ones
	MOVN G,JCNT
	HRLZS G
	MOVEM G,GSAVE#		;May be needed again later
	MOVSI Q,-4
JGIN1:	PUSHJ P,JPARAM		;Read a parameter
	JUMPE B,JGIN3		;B=0 means no number before symbol
	MOVEM A,JPMAR(Q)
	SOS Q			;Q-right left with count of unspecified fields
JGIN3:	CAIN C,","		;Any other symbol terminates JGINIT
	AOBJN Q,JGIN1
	POPJ P,

;  Subroutine called by JGMAR
;If entered with B=0, will locate the first non-blank line after 1 or  more
;blank lines and return the number of blank lines in B.
;If entered with B<0, will continue to end of specified text, returning the
;length of the longest line encountered in Q.
;Pointer to the first line of text in D and the specification of the number
;of lines of text (as a negative number) in the left of G.
JGB0:	HRRZ D,(D)
JGB:	HRRZ C,TXTCNT(D)
	JUMPN C,JGB1
	SKIPL B			;Don't change B if it is neg
	AOJA B,JGB2		;Count blank lines for JBNUM
JGB1:	CAMLE C,Q
	MOVE Q,C		;Put largest in Q for JRMAR
	JUMPLE B,JGB2		;Continue to end of text if B<0
	MOVEM B,JBNUMO		;Save it here always
	SKIPGE JBNUM		;Was a JBNUM typed in?
	MOVEM B,JBNUM		;No, so use this value
	MOVEM G,GSAVE		;May be needed twice
	MOVEM D,JPTR		;Save new starting place in text
	POPJ P,
JGB2:	AOBJN G,JGB0
	MOVE D,JPTR
	POPJ P,

;To get indentation
JGIND:	HRRZ T,TXTCNT(D)
	MOVNS T
	HRLZS T
	MOVE A,D
	ADD A,[440700,,LLDESC]
JGIND1:	ILDB C,A
	CAIN C,11		;Is it a TAB?
	JRST JGIND1		;Ignore it
	CAIN C," "		;Is it a space?
	AOBJN T,JGIND1		;Count it
	POPJ P,

;   Subroutine called by
;To determine margins from specified text
JGMAR:	MOVN G,JCNT
	HRLZS G
	MOVEM G,GSAVE		;May be needed twice
	SETZB B,Q		;B counts blank lines, Q gets JRMAR
	MOVE D,JPTR		;Pointer to the first line of text
	PUSHJ P,JGB		;Find paragraph start
	PUSHJ P,JGIND		;Get its indentation
	MOVEM T,INDCNT#		;May be needed for TJGET case
	MOVEM A,ASAVE#		;and also pointer to first non-blank character
	HRRZM T,JPMARO		;Save it always
	SKIPGE JPMAR		;Was a new value typed?
	HRRZM T,JPMAR		;No, so use this value
	AOBJN G,JGM0		;Trouble, not enough lines
	OUTSTR [ASCIZ/Not enough lines, will set LMAR to PMAR. /]
	JRST JGMA
JGM0:	HRRZ D,(D)
	PUSHJ P,JGIND		;Get indentation of the next line
JGMA:	SKIPGE JLMAR		;Was a new value typed?
	HRRZM T,JLMAR		;No, so save this value
	SKIPLE JRMAR		;Was a new JRMAR typed in?
	POPJ P,
	JUMPE B,JGM1		;Have we been to the end of the text?
	SETO B,
	PUSHJ P,JGB		;No so do it now
JGM1:	MOVEM Q,JRMAR		;No, so save this value
	POPJ P,

;To test margins for legality
JMTEST:	MOVE A,JPMAR
	CAME A,JLMAR
	JRST JMTES1
	SKIPLE JBNUM
	JRST JMTES1
	MOVEI T,1
	MOVEM T,JBNUM		;Must be ≥1 in this case
	OUTSTR [ASCIZ/BNUM set to 1./]
JMTES1:	CAMG A,JLMAR
	MOVE A,JLMAR
	ADDI A,MINTXT		;Minimum text length
	CAMG A,JRMAR
	POPJ P,
	MOVEM A,JRMAR
	OUTSTR [ASCIZ/ RMAR set to /]
	TYPDEC A
	OUTSTR [ASCIZ/ /]
	POPJ P,

;Get typed-in margins and/or values identified from the specified text.
JGET:	PUSHJ P,JGINIT		;Initialize and get typed-in margin values
	CAIN C,";"		;To avoid confusion with TJGET
	OUTSTR [ASCIZ/Caution, no TAB values allowed with JGET command./]
	SKIPE JCNT
	PUSHJ P,JGMAR		;Get margins by examining the text
	PUSHJ P, ABCRLF
	PUSHJ P,JMTEST		;Test margins for legality
	OUTSTR [ASCIZ/Margins (P,L,R,B) are /]
	MOVSI G,-4
	SETZM TYOPNT
	SKIPA
JGET1:	OUTSTR [ASCIZ/,/]
	MOVE A,JPMAR(G)
	MOVEM A,PMARS(G)
	TYPDEC A
	AOBJN G,JGET1
	POPJ P,
	
;Get margins and also TAB settings
TJGET:	PUSHJ P,JGINIT		;Initialize and get typed margin values
	MOVSI Q,-TABCNT
	SKIPG JCNT
	JRST TJG1
	SETOM TABTAB(Q)		;Set TABTAB to -1 if JCNT>0
	AOBJN Q,.-1
	JRST TJG2
TJG1:	CAIE C,";"
	CAIN C,"!"
	SKIPA
	JRST TJG7		;No typed TAB values
	HLLZS TABTAB(Q)		;Zero indent values only
	AOBJN Q,.-1
TJG2:	MOVSI Q,-TABCNT
	CAIN "!"
	JRST TJG4A		;Next number is to be an indent not a field size
TJG3:	PUSHJ P,JPARAM
	CAIE C,"@"		;Is this a multiple define
	JRST TJG5
	MOVE H,A		;Yes, so save repetition number in H
	PUSHJ P,JPARAM		;and get field size
TJG4:	SKIPE A			;A zero or missing value means leave unchanged
	HRLZM A,TABTAB(Q)
	AOBJP Q,TJG7A		;No more space so ignore the rest
	SOJG H,TJG4
	JRST TJG6		;See if there are any more

TJG4A:	PUSHJ P,JPARAM		;Get indent value
	JUMPG A,TJG4B		;An indent can not be zero
	OUTSTR [ASCIZ/IMPROPER SYNTAX, a non-zero number must follow a "!" symbol/]
	POPJ P,
TJG4B:	HRRZM A,TABTAB(Q)
	AOBJP Q,TJG7A
	JRST TJG6

TJG5:	JUMPE B,TJG6		;Was a number typed?
	HRLZM A,TABTAB(Q)	;Yes, so save it as a field length
TJG6:	CAIN C,","
	JRST TJG3
	CAIN C,"!"
	JRST TJG4A

TJG7A:	OUTSTR [ASCIZ/ Too many TABs typed,, will ignore rest /]
TJG7:	SKIPN JCNT		;Are values to be deduced from the text?
	JRST TJG18		;No
	PUSHJ P,JGMAR		;Get margins from the text
	MOVSI Q,-TABCNT
	MOVE A,ASAVE		;Get back to the first non-space char in 1st line
	MOVE G,INDCNT		;Get character counter for first non-space
	SETZB T,H		;T counts field, H for testing for spaces or TABs
TJG8:	AOS T			;We start on the first char
	ILDB C,A
	CAIE C," "
	CAIN C,11
	JRST TJG11		
	SETZ H,			
TJG8A:	AOBJN G,TJG8
	JRST TJG15

;To count spaces or TABS for field termination determination
TJG9:	AOS T
TJG10:	ILDB C,A
TJG11:	CAIE C," "		;Is it a space?
	JRST TJG12
	AOS H
	AOBJN G,TJG9
	JRST TJG15

TJG12:	CAIN C,11		;or a TAB?
	AOJA H,TJG10		;TABs do not count in G but add to H
	CAIL H,TJSCNT		;TAB terminating space count
	JRST TJG13		;At end of this TAB field
	SETZ H,			;Single spaces are allowed in a field
	AOBJN G,TJG9
	JRST TJG15

TJG13A:	OUTSTR [ASCIZ/ Only /]
	MOVEI A,TABCNT
	TYPDEC A
	OUTSTR [ASCIZ/ TABS allowed. /]
	JRST TJG15

TJG13:	SKIPG TABTAB(Q)
	MOVEM T,TABTAB(Q)
	AOBJP Q,TJG13A
	SETZ T,
	AOBJN G,TJG8
TJG15:	MOVSI Q,-TABCNT
	MOVE TT,JPMAR
TJG16:	SKIPGE TABTAB(Q)
	JRST TJG18		;No more values specified
	HLRZ T,TABTAB(Q)
	JUMPE T,TJG17		;An indent was specified
	ADD TT,T		;Compute a new indent
	HRRM TT,TABTAB(Q)
	AOBJN Q,TJG16
	JRST TJG18


TJG17:	HRRZ T,TABTAB(Q)
	SUB T,TT
	CAIL T,MINTXT
	JRST TJG17A		;Field would be too small
	OUTSTR [ASCIZ/ TAB field #/]
	HRRZ C,Q
	TYPDEC C
	OUTSTR [ASCIZ/ set at min of /]
	MOVEI T,MINTXT
	TYPDEC T
	OUTSTR [ASCIZ/ /]
TJG17A:	HRLM T,TABTAB(Q)
	ADD TT,T
	HRRM TT,TABTAB(Q)	;May have been corrected
	AOBJN Q,TJG16
	JRST TJG18

TJG18:	OUTSTR [ASCIZ/Margins P,L,R,B) are /]

	SETZM TYOPNT
	MOVSI Q,-4		;Report values
	SKIPA
TJG19:	OUTSTR [ASCIZ /,/]
	MOVE T,JPMAR(0)
	MOVEM T,TPMAR(Q)
	TYPDEC T
	AOBJN Q,TJG19

	OUTSTR [ASCIZ/ TAB fields of /]
	MOVSI Q,-TABCNT
	SKIPA
TJG20:	OUTSTR [ASCIZ/,/]
	HLRZ T,TABTAB(Q)
	SKIPL TABTAB+1(Q)
	AOBJN Q,TJG20
TJG21:	OUTSTR [ASCIZ/ Starting at /]
	MOVE T,JPMAR
	ADDI T
	TYPDEC T
	MOVSI Q,-TABCNT
	SKIPA
TJG22:	OUTSTR [ASCIZ/,/]
	HRRZ T,TABTAB(Q)
	ADDI T,1
	TYPDEC T
	SKIPL TABTAB+1(Q)
	AOBJN Q,TJG22
	POPJ P,